<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta name="description" content="对网页的一段概括性描述" />
<meta name="keywords" content="关键字1,关键字2,关键字3..." />
<meta name="renderer" content="webkit">
<title>Hiring-企业后台</title>
  <%@ include file="/WEB-INF/view/common/import.jsp"%>
</head>
<body >
	<div class="container">
		<strong class="welcome-title">${companyEntity.name }</strong> <a
			class="btn btn-warning"
			href="<%=request.getContextPath()%>/CompanyServlet?command=gocompanyDetailUI&id=${sessionScope.companyEntity.id}">详细信息</a>
		<a type="button" class="btn btn-warning pull-right" style="margin-left: 10px"
			href="<%=request.getContextPath()%>/CompanyServlet?command=logout">注销</a>
		<a type="button" class="btn btn-warning pull-right"
			href="<%=request.getContextPath()%>/CompanyServlet?command=goHomepageUI">主页</a>
		<hr />
		<a href="PositionServlet?command=goAddPositionUI"><h2>新增职位</h2></a>
		<table class="table table-hover">
			<tr>
				<th>序号</th>
				<th>职位名称</th>
				<th>职责</th>
				<th>所需能力</th>
				<th>薪资</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
			<c:if test="${not empty positionList }">
				<c:forEach items="${positionList }" var="positionList" varStatus="v">
					<tr>
						<td>${v.count }</td>
						<td>${positionList.name }</td>
						<td>${positionList.duty }</td>
						<td>${positionList.ability }</td>
						<td>${positionList.salary1 }-${positionList.salary2 }</td>
						<td>${fn:substring(positionList.releaseTime,0,19) }</td>
						<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
						<td><a
							href="PositionServlet?command=updateQuery&id=${positionList.id }"
							title="修改">修改</a>| <a href="javascript:void(0);"
							onclick="del(this,${positionList.id})" title="删除">删除</a></td>
					</tr>
				</c:forEach>
			</c:if>
			<c:if test="${empty positionList }">
				<tr class="danger">
					<td colspan="7" align="center">暂无数据!</td>
			</c:if>
		</table>



		
		
		<br>
		<h2>收到的求职信息:</h2>
		<table class="table table-hover">
			<tr>
				<th>序号</th>
				<th>职位名称</th>
				<th>求职者姓名</th>
				<th>申请时间</th>
				<th>审核状态</th>
				<th>是否通过审核</th>
				<th>操作</th>
			</tr>
			<c:if test="${not empty applicationEntity }">
				<c:forEach items="${applicationEntity }" var="applicationEntity" varStatus="v">
					<tr>
						<td>${v.count }</td>
						<td>${applicationEntity.position$name }</td>
						<td>${applicationEntity.talent$name }<a href="<%=request.getContextPath()%>/CompanyServlet?command=goResumeDetailUI&talentId=${applicationEntity.talent$id}" class="btn btn-info btn-xs">查看简历</a></td>
						<td>${fn:substring(applicationEntity.appTime,0,19) }</td>
						<c:if test="${applicationEntity.status==1 }">
						<td id="status"><span style="color:green">通过审核</span></td>
						</c:if>
						<c:if test="${applicationEntity.status==2 }">
						<td id="status"><span id="statusColor" style="color:red">未通过审核</span></td>
						</c:if>
						<c:if test="${applicationEntity.status==3 }">
						<td id="status"><span style="color:gray">待审核</span></td>
						</c:if>
						<td>
							<a href="javascript:void(0)" class="btn btn-success btn-xs" onclick="updateStatus(this,${applicationEntity.id},1)">通过</a>&nbsp;&nbsp;&nbsp;
							<a href="javascript:void(0)" class="btn btn-danger btn-xs" onclick="updateStatus(this,${applicationEntity.id},2)">拒绝</a>
						</td>
						<td>
							<a href="javascript:void(0)" class="btn btn-danger btn-xs" onclick="deleteApplication(this,${applicationEntity.id})">删除</a>
						</td>
					</tr>
				</c:forEach>
			</c:if>
			<c:if test="${empty applicationEntity }">
				<tr class="danger">
					<td colspan="7" align="center">暂无数据!</td>
			</c:if>
		</table>
		

	</div>


	<script>
		function deleteApplication(obj, applicationId){
			layer.confirm('确认删除？', {
				  btn: ['确认','取消'] //按钮
				}, function(){
					 $.get('<%=request.getContextPath()%>/CompanyServlet?command=deleteApplication&applicationId=' + applicationId + '&time=' + new Date().getTime(), function(text){
					     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
					     if (text == 'fail') {
					    	layer.msg('操作失败！', {time: 2000, icon: 5});
					     } else {
					    	layer.msg('操作成功！', {time: 1000, icon: 6});
					    	$(obj.parentNode.parentNode).remove();
					     }
					  });
				}, function(){
				  });
			}
		
		function del(obj, positionId) {
    			// 创建XMLHttpRequest。我在页面上不动，我准备委托一个人去帮我删除数据
    			var xmlhttp;
				if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
				  xmlhttp=new XMLHttpRequest();
				} else { // code for IE6, IE5
				  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				
    			// XMLHttpRequest请求。我把这个人派出去
    			xmlhttp.open('GET', '<%=request.getContextPath()%>/PositionServlet?command=delete&positionId=' + positionId + '&time=' + new Date().getTime(), true);
				xmlhttp.send();
    			
				// 随时与这个人保持联系，方便及时知道结果
				xmlhttp.onreadystatechange=function() {
		    	  // XMLHttpRequest响应。这个人把事情做完了（删除数据），然后回来告诉我
				  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				    var text = xmlhttp.responseText;
				    // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
				    if (text == 'fail') {
				    	layer.msg('操作失败！', {time: 2000, icon: 5});
				    } else {
				    	layer.msg('操作成功！', {time: 2000, icon: 6});
				    	$(obj.parentNode.parentNode).remove();
				    }
				  }
				}
		  
		  /*
		  // $.get(url, function(data) {})
		  $.get('<%=request.getContextPath()%>/ResumeServlet?command=delete&resumeId=' + resumeId + '&time=' + new Date().getTime(), function(text){
		     // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
		     if (text == 'fail') {
		    	layer.msg('操作失败！', {time: 2000, icon: 5});
		     } else {
		    	layer.msg('操作成功！', {time: 2000, icon: 6});
		    	$(obj.parentNode.parentNode).remove();
		     }
		  });
		  */
		}
		
		function updateStatus(obj, applicationId,status) {
			// 创建XMLHttpRequest。我在页面上不动，我准备委托一个人去帮我删除数据
			var xmlhttp;
			if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			} else { // code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			// XMLHttpRequest请求。我把这个人派出去
			xmlhttp.open('GET', '<%=request.getContextPath()%>/ApplicationServlet?command=updateStatus&applicationId=' + applicationId + '&time=' + new Date().getTime()+'&status='+status, true);
			xmlhttp.send();
			
			// 随时与这个人保持联系，方便及时知道结果
			xmlhttp.onreadystatechange=function() {
	    	  // XMLHttpRequest响应。这个人把事情做完了（删除数据），然后回来告诉我
			  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			    var text = xmlhttp.responseText;
			    // 如果是成功了就在页面上删除当前a标签所在的tr，如果不成功给出提示
			    if (text == 'success') {
			    	if(status==1){
			    		//obj.innerHTML="通过审核";
			    		document.getElementById("status").innerHTML="通过审核";
			    		document.getElementById("statusColor").style="color:green";
			    	}else if(status==2){
			    		document.getElementById("status").innerHTML="未通过审核";
			    		document.getElementById("statusColor").style="color:red";
			    		//obj.innerHTML="未通过审核";
			    	}	
			    	
			    } else {
			    	layer.msg('操作失败！', {time: 2000, icon: 5});
			    }
			  }
			}
		}
		</script>
	
</body>

</html>
